#include <ansi_c.h>
#define SIZE 6
#define nr 'n'
#define bl 'b'
#define ab ' '
#define x  'x'
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DE LA FONCTION PRINCIPALE*/
void detection(char tab[SIZE][SIZE]);
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*PROTOTYPE DES FONCTIONS CASES X*/ 
char case_haut_gauche(char,int,int);
char case_haut_centre(char,int,int);   
char case_haut_droite(char,int,int);  
char case_milieu_gauche(char,int,int);  
char case_milieu_droite(char,int,int);  
char case_bas_gauche(char,int,int);   
char case_bas_centre(char,int,int);  
char case_bas_droite(char,int,int);
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*VARIABLE GENERALE*/
char tab[SIZE][SIZE]={  {ab,ab,ab,ab,ab,ab},
 				 		{ab,ab,ab,ab,ab,ab}, 		 
 				 		{ab,ab,bl,nr,ab,ab}, 
 				 		{ab,ab,nr,bl,ab,ab}, 			 
						{ab,ab,ab,ab,ab,ab}, 
						{ab,ab,ab,ab,ab,ab}, 
 					  };
char case_next='0';  
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION MAIN*/
void main(void)
{
 int i;
 int j;
 int b=0;
 int n=0;

 for(i=0;i<SIZE;i++)				 
 {									 
  printf("\n");
  for(j=0;j<SIZE;j++)				  
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 printf("\n\n");
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
 detection(tab);
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
														/*FONCTION PRINCIPALE*/
void detection(char tab[SIZE][SIZE])
{
 int i;
 int j;
 int b=0;
 int n=0;
 int k=0;
 for(i=0 ; i<SIZE ; i++)
 {
  for(j=0 ; j<SIZE ; j++)
  {
   if(tab[i][j]==bl)
   {
	tab[i-1][j-1]=case_haut_gauche(tab[i-1][j-1],i,j);
	tab[i-1][j]=case_haut_centre(tab[i-1][j],i,j);   
	tab[i-1][j+1]=case_haut_droite(tab[i-1][j+1],i,j);   	   
	tab[i][j-1]=case_milieu_gauche(tab[i][j-1],i,j);   
	tab[i][j+1]=case_milieu_droite(tab[i][j+1],i,j);   
	tab[i+1][j-1]=case_bas_gauche(tab[i+1][j-1],i,j);   
	tab[i+1][j]=case_bas_centre(tab[i+1][j],i,j);   
	tab[i+1][j+1]=case_bas_droite(tab[i+1][j+1],i,j);   
   }
  }
 }
/*------------------------------------------------------------------------------------------------------------------------------------------*/
 														/*AFFICHE DE NOUVEAUX LE TABLEAUX*/
 for(i=0;i<SIZE;i++)				 
 {									 
  printf("\n");
  for(j=0;j<SIZE;j++)				  
  {
   printf("\t%c",tab[i][j]);
   if(tab[i][j]==bl)
	   b=b+1;
   else if (tab[i][j]==nr)
	   n=n+1;
  }
 printf("\n\n");
 }
 printf("\n\n");
 printf("\npoint blanc :%d\t\tpoint noir :%d",b,n);
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_gauche(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i-2][j-2]==ab)
  {
   tab[i-2][j-2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i-2][j-2];
    i=i-1;
    j=j-1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_centre(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i-2][j]==ab)
  {
   tab[i-2][j]=x;
  }
  else
  {
   do
   {
    case_next=tab[i-2][j];
    i=i-1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_haut_droite(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i-2][j+2]==ab)
  {
   tab[i-2][j+2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i-2][j+2];
    i=i-1;
    j=j+1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i-1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i-1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_milieu_gauche(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i][j-2]==ab)
  {
   tab[i][j-2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i][j-2];
    j=j-1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_milieu_droite(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i][j+2]==ab)
  {
   tab[i][j+2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i][j+2];
    j=j+1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_gauche(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i+2][j-2]==ab)
  {
   tab[i+2][j-2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i+2][j-2];
    i=i+1;
    j=j-1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j-1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j-1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_centre(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i+2][j]==ab)
  {
   tab[i+2][j]=x;
  }
  else
  {
   do
   {
    case_next=tab[i+2][j];
    i=i+1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
char case_bas_droite(char caract,int i,int j)
{
 if(caract==bl)
 {
 }
 else if(caract==nr)
 {
  if(tab[i+2][j+2]==ab)
  {
   tab[i+2][j+2]=x;
  }
  else
  {
   do
   {
    case_next=tab[i+2][j+2];
    i=i+1;
    j=j+1;
   }
   while(case_next==nr);
   if(case_next==bl)
   {
    tab[i+1][j+1]=case_next;
   }
   else if(case_next==ab)
   {
	case_next=x;
    tab[i+1][j+1]=case_next;
   }
  }
 }
 return caract;
}
/*------------------------------------------------------------------------------------------------------------------------------------------*/
